﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.SelfIssuedAuthAsymmetricKey
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.IdentityModel.Tokens;
using System.Security.Cryptography;

namespace Microsoft.InfoCards
{
  internal class SelfIssuedAuthAsymmetricKey : AsymmetricSecurityKey, IDisposable
  {
    private SelfIssuedAuthRSACryptoProvider m_selfIssuedAuthRsaCryptoProvider;

    public SelfIssuedAuthAsymmetricKey(RSACryptoServiceProvider rsa)
    {
      this.m_selfIssuedAuthRsaCryptoProvider = new SelfIssuedAuthRSACryptoProvider(rsa);
    }

    public override int KeySize
    {
      get
      {
        return this.m_selfIssuedAuthRsaCryptoProvider.KeySize;
      }
    }

    public override bool HasPrivateKey()
    {
      InfoCardTrace.ThrowInvalidArgumentConditional(this.m_selfIssuedAuthRsaCryptoProvider.IsPublicOnly(), "selfIssuedRsaCrypoProvider");
      return true;
    }

    public override AsymmetricAlgorithm GetAsymmetricAlgorithm(
      string algorithmUri,
      bool privateKey)
    {
      switch (algorithmUri)
      {
        case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
        case "http://www.w3.org/2001/04/xmlenc#rsa-1_5":
        case "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p":
          return (AsymmetricAlgorithm) this.m_selfIssuedAuthRsaCryptoProvider;
        default:
          throw InfoCardTrace.ThrowHelperError((Exception) new NotSupportedException(SR.GetString("ClientUnsupportedCryptoAlgorithm", (object) algorithmUri)));
      }
    }

    public override HashAlgorithm GetHashAlgorithmForSignature(string algorithmUri)
    {
      switch (algorithmUri)
      {
        case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
          return (HashAlgorithm) new SHA1Managed();
        default:
          throw InfoCardTrace.ThrowHelperError((Exception) new NotSupportedException(SR.GetString("UnsupportedSignatureAlgorithm", (object) algorithmUri)));
      }
    }

    public override AsymmetricSignatureDeformatter GetSignatureDeformatter(
      string algorithmUri)
    {
      switch (algorithmUri)
      {
        case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
          return (AsymmetricSignatureDeformatter) new SelfIssuedAuthRSAPKCS1SignatureDeformatter((AsymmetricAlgorithm) this.m_selfIssuedAuthRsaCryptoProvider);
        default:
          throw InfoCardTrace.ThrowHelperError((Exception) new NotSupportedException(SR.GetString("UnsupportedSignatureAlgorithm", (object) algorithmUri)));
      }
    }

    public override AsymmetricSignatureFormatter GetSignatureFormatter(
      string algorithmUri)
    {
      switch (algorithmUri)
      {
        case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
          return (AsymmetricSignatureFormatter) new SelfIssuedAuthRSAPKCS1SignatureFormatter((AsymmetricAlgorithm) this.m_selfIssuedAuthRsaCryptoProvider);
        default:
          throw InfoCardTrace.ThrowHelperError((Exception) new NotSupportedException(SR.GetString("UnsupportedSignatureAlgorithm", (object) algorithmUri)));
      }
    }

    public override byte[] DecryptKey(string algorithmUri, byte[] keyData)
    {
      throw InfoCardTrace.ThrowHelperError((Exception) new NotSupportedException());
    }

    public override byte[] EncryptKey(string algorithmUri, byte[] keyData)
    {
      throw InfoCardTrace.ThrowHelperError((Exception) new NotSupportedException());
    }

    public override bool IsSupportedAlgorithm(string algorithmUri)
    {
      switch (algorithmUri)
      {
        case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
        case "http://www.w3.org/2001/04/xmlenc#rsa-1_5":
        case "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p":
          return true;
        default:
          return false;
      }
    }

    public override bool IsSymmetricAlgorithm(string algorithmUri)
    {
      return InfoCardCryptoHelper.IsSymmetricAlgorithm(algorithmUri);
    }

    public override bool IsAsymmetricAlgorithm(string algorithmUri)
    {
      return InfoCardCryptoHelper.IsAsymmetricAlgorithm(algorithmUri);
    }

    public void Dispose()
    {
      if (this.m_selfIssuedAuthRsaCryptoProvider == null)
        return;
      ((IDisposable) this.m_selfIssuedAuthRsaCryptoProvider).Dispose();
      this.m_selfIssuedAuthRsaCryptoProvider = (SelfIssuedAuthRSACryptoProvider) null;
    }
  }
}
